const { success, notFound, error } = require('../utils/response');
const categoryModel = require('../models/categoryModel');

const getAllCategories = async (req, res) => {
  try {
    const categories = await categoryModel.getAllCategories();
    success(res, categories);
  } catch (err) {
    error(res, err.message);
  }
};

const getCategoryById = async (req, res) => {
  try {
    const category = await categoryModel.getCategoryById(req.params.id);
    if (!category) {
      return notFound(res, 'Category not found');
    }
    success(res, category);
  } catch (err) {
    error(res, err.message);
  }
};

module.exports = {
  getAllCategories,
  getCategoryById
};